using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Collections.Generic;

/// <summary>
/// Summary description for CustomerDAO
/// </summary>
public class CustomerDAO:DBAccess
{
    string SQL_SELECT_ALL = "select * from Customers";
	public CustomerDAO()
	{
		//
		// TODO: Add constructor logic here
		//
	}
    public IList<CustomerInfo> GetAll()
    {
        IList<CustomerInfo> list = new List<CustomerInfo>();
        try
        {
            SqlCommand command = new SqlCommand(SQL_SELECT_ALL, conn);
            if (Connect())
            {
                SqlDataReader dr=command.ExecuteReader();
                while (dr.Read())
                {
                    CustomerInfo customer = new CustomerInfo();
                    customer.CustomerId = dr.GetInt32(0);
                    customer.CompanyName = dr.GetString(1);
                    if (!dr.IsDBNull(2)) customer.ContactName = dr.GetString(2);
                    if (!dr.IsDBNull(3)) customer.ContactTitle = dr.GetString(3);
                    if (!dr.IsDBNull(4)) customer.Address = dr.GetString(4);
                    if (!dr.IsDBNull(5)) customer.City = dr.GetString(5);
                    if (!dr.IsDBNull(6)) customer.Region = dr.GetString(6);
                    if (!dr.IsDBNull(7)) customer.PostalCode = dr.GetString(7);
                    if (!dr.IsDBNull(8)) customer.Country = dr.GetString(8);
                    if (!dr.IsDBNull(9)) customer.Phone = dr.GetString(9);
                    if (!dr.IsDBNull(10)) customer.Fax = dr.GetString(10);
                    list.Add(customer);
                }
                Disconnect();
            }
        }
        catch (SqlException ex) { }
        catch (Exception ex) { }
        return list;
    }
}
